Skip to content

Conversation

gaberudy
Copy link

I did this for my needs but realized there is a closed issue (not implemented) that is requesting the same thing.

Through the idle-timeout arg or IDLE_TIMEOUT environment variable, after the specified number of minutes since the heartbeat was last refreshed is detected, the code-server process shuts down. When run as the single process of a docker container, this just stops the container.

Fixes #1636

@gskifstad
Copy link

hi! our team would love this feature as well. I see there is a stray merge conflict causing linter errors, but otherwise, is there anything blocking this PR?

@code-asher
Copy link
Member

Yeah happy to merge this in if the conflicts and below are addressed.

I think the heart counting inactivity and directly exiting the process is more than it should be doing. Maybe we could refactor so the heart has an onChange event that is called when the state changes to either active or inactive? Then we can tie it all together in entry.ts.

// could propagate the event through `server` or maybe we could just pass the `heart` itself back
server.onChange((state) => {
  if (state === "active") {
    clearTimeout(timer)
  } else if (args["idle-timeout"]) {
    timer = setTimeout(() => {
      logger.warn(`Idle timeout of ${args["idle-timeout"]} minutes exceeded`)
      wrapper.exit();
    }, args["idle-timeout"] * 60 * 1000);
  }
})

Something like that.

I think if we have the flag as idle-timeout we might want to have it in seconds by default and allow m or h or s suffixes? Or change the flag to idle-timeout-minutes or something.

One other thing, we should check the parseInt for NaN.

@code-asher
Copy link
Member

Closing for now but happy to re-review if you come back to this.

@code-asher code-asher closed this Aug 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add --idle-timeout to shutdown code-server when there isn't an active connection

3 participants